import axios from 'axios'

const http = axios.create({
  baseURL: '/api',
  timeout: 30000
})

// 请求拦截器
http.interceptors.request.use((config) => {

  return config
})

// 响应拦截器
http.interceptors.response.use((response) => {
  return response.data
}, (err) => {
  return Promise.reject(err)
})


export function httpGet(url: string, params: any = {}) {
  return new Promise((resolve, reject) => {
    http.get(
      url,
      { params }
    )
      .then(res => {
        resolve(res)
      })
      .catch((err) => {
        ElMessage.error('请求失败')
        reject(err)
      })
  })
}

